RAIS  3.2
C:/Projekte/RAIS/Specific Masks/CustomTables1_New.aspx.cs
Go to the documentation of this file.
00001 using System;
00002 using System.Data;
00003 using System.Configuration;
00004 using System.Collections;
00005 using System.Web;
00006 using System.Web.Security;
00007 using System.Web.UI;
00008 using System.Web.UI.WebControls;
00009 using System.Web.UI.WebControls.WebParts;
00010 using System.Web.UI.HtmlControls;
00011 
00012 using RAIS.Common.TableManagement;
00013 using RAIS.Common.UserManagement;
00014 using RAIS.UI.Common;
00015 
00016 using TableGroups = System.Collections.Generic.Dictionary<string, RAIS.Common.TableManagement.TableGroup>;
00017 using Tables = System.Collections.Generic.Dictionary<string, RAIS.Common.TableManagement.Table>;
00018 
00019 namespace RAIS.UI.SpecificMasks
00020 {
00024     public partial class CustomTables1_New : System.Web.UI.Page
00025     {
00026                 //*********************************************************************
00027                 #region Private properties
00028 
00031                 protected UserData CurrentUser
00032                 {
00033                         get { return (UserData)this.Session[UI.Common.Constants.CURRENT_USER_TAG]; }
00034                 }
00038                 private TableGroup SelectedTableGroup
00039                 {
00040                         get
00041                         {
00042                                 TableGroups tableGroups = RAIS.ApplicationLogicLayer.TableManagement.TableGroups;
00043                                 if (tableGroups != null && tableGroups.ContainsKey(this.DDLtablegroup.SelectedValue))
00044                                         return tableGroups[this.DDLtablegroup.SelectedValue];
00045                                 else
00046                                         return null;
00047                         }
00048                 }
00052                 private RAIS.Common.TableManagement.Table SelectedTable
00053                 {
00054                         get
00055                         {
00056                                 //Tables tables = RAIS.ApplicationLogicLayer.TableManagement.GetCustomTablesByGroup(this.SelectedTableGroup);
00057                                 Tables tables = (Tables)this.Session[RAIS.UI.Common.Constants.TABLES_TAG];
00058                                 if (tables != null && tables.ContainsKey(this.LBtable.SelectedValue))
00059                                         return tables[this.LBtable.SelectedValue];
00060                                 else
00061                                         return null;
00062                         }
00063                 }
00067                 protected bool ShowHidden
00068                 {
00069                         get
00070                         {
00071                                 //if (this.Session[UI.Common.Constants.SHOW_HIDDEN_STATE_TAG] != null)
00072                                 //    return (bool)this.Session[UI.Common.Constants.SHOW_HIDDEN_STATE_TAG];
00073                                 //else
00074                                 //    return false;
00075                                 return UI.Common.PageManagement.GetShowProtectors(this)
00076                                         || UI.Common.PageManagement.GetShowEvaluators(this);
00077                         }
00078                         set
00079                         {
00080                                 this.Session[UI.Common.Constants.SHOW_HIDDEN_STATE_TAG] = value;
00081                         }
00082                 }
00086                 protected bool ShowProtectors
00087                 {
00088                         get
00089                         {
00090                                 return UI.Common.PageManagement.GetShowProtectors(this);
00091                         }
00092                 }
00096                 protected bool ShowEvaluators
00097                 {
00098                         get
00099                         {
00100                                 return UI.Common.PageManagement.GetShowEvaluators(this);
00101                         }
00102                 }
00103                 #endregion Private properties
00104                 //*********************************************************************
00105                 #region Event handlers
00106         protected void Page_PreLoad(object sender, EventArgs e)
00107         {
00108             RAIS.UI.Common.PageManagement.TrimTextBoxValues(this);
00109         }
00116                 protected void Page_Load(object sender, EventArgs e)
00117         {
00118                         this.Response.Cache.SetNoStore();
00119                         if (this.CurrentUser == null)
00120                                 UI.Common.AccessManagement.SignOut(this);
00121 
00122                         this.LBLresult.Text = string.Empty;
00123                         if (!this.IsPostBack)
00124                         {
00125                 this.LBLusernameNoTranslation.Text = this.CurrentUser.Name;
00126 
00127                                 //this.CBshowHidden.Visible =
00128                                 //    (this.CurrentUser.FunctionalRole.Type == FunctionRole.FunctionRoleType.Administrator);
00129                                 //this.CBshowHidden.Checked = this.ShowHidden;
00130                 this.LBLadmin.ForeColor = RAIS.UI.Common.Constants.COLOR_OF_MENU_BAR_TEXT_HIGHLIGHT;    
00131                                 UI.Common.TableManagement.InitializeTableGroupList(this.DDLtablegroup);
00132                                 this.Session[Constants.SAVED_GROUP_TAG] = this.SelectedTableGroup;
00133                                 UI.Common.TableManagement.InitializeTableListBoxByGroup(this.LBtable, this.SelectedTableGroup, this.ShowProtectors, this.ShowEvaluators);
00134                                 this.Session[Constants.TABLE_NAME_TAG] = this.SelectedTable.Name;
00135                 CreateProtectors();
00136                                 this.EnableDeleteButton();
00137                                 this.EnableEditButton();
00138                                 this.EnableCreateHistoryTableButton();
00139                                 this.SetFocus(this.LBtable);
00140 
00141                                 UI.Common.PageManagement.InitializePage(this, this.TreeView1);
00142 //                              this.LBTNmessagebox.Visible = !(this.CurrentUser.FunctionalRole.Type == FunctionRole.FunctionRoleType.Guest);
00143                         }
00144             PageManagement.InitHelpMainMenu(LBTNdefault);
00145                 }
00152                 protected void Page_Init(object sender, EventArgs e)
00153         {
00154             PageManagement.SetScrolableListBox(LBtable, this, true);
00155         }
00161                 protected void CBshowHidden_CheckedChanged(object sender, EventArgs e)
00162                 {
00163                         this.ShowHidden = CBshowHidden.Checked;
00164                         this.Session[RAIS.UI.Common.Constants.TABLES_TAG] = null;
00165                         UI.Common.TableManagement.InitializeTableListBoxByGroup(this.LBtable, this.SelectedTableGroup, this.ShowProtectors, this.ShowEvaluators);
00166                 }
00172                 protected void DDLtablegroup_SelectedIndexChanged(object sender, EventArgs e)
00173                 {
00174                         this.Session[Constants.SAVED_GROUP_TAG] = this.SelectedTableGroup;
00175                         this.Session[Constants.TABLE_NAME_TAG] = null;
00176 
00177                         UI.Common.TableManagement.InitializeTableListBoxByGroup(this.LBtable, this.SelectedTableGroup, this.ShowProtectors, this.ShowEvaluators);
00178             CreateProtectors();
00179                         this.EnableDeleteButton();
00180                         this.EnableEditButton();
00181                         this.EnableCreateHistoryTableButton();
00182                         this.SetFocus(this.LBtable);
00183                 }
00189                 protected void LBtable_SelectedIndexChanged(object sender, EventArgs e)
00190                 {
00191                         this.Session[Constants.TABLE_NAME_TAG] = this.SelectedTable.Name;
00192             CreateProtectors();
00193                         this.EnableDeleteButton();
00194                         this.EnableEditButton();
00195                         this.EnableCreateHistoryTableButton();
00196                         this.SetFocus(this.LBtable);
00197                 }
00204                 protected void BTNedit_Click(object sender, EventArgs e)
00205                 {
00206                         Response.Redirect(string.Format("~/CustomTables3_New.aspx?{0}={1}"
00207                                 , Constants.TABLE_ID_PARAMETER_NAME, this.SelectedTable.ID));
00208                 }
00215                 protected void BTNdelete_Click(object sender, EventArgs e)
00216                 {
00217                         RAIS.Common.TableManagement.Table selectedTable = this.SelectedTable;
00218 
00219                         if (selectedTable != null)
00220                         {
00221                                 string returnMessage = string.Empty;
00222                 if (selectedTable.HistoryTable)
00223                 {
00224                     this.LBtable.SelectedValue = GetParentTableForHistory(selectedTable).Name;
00225                     selectedTable = this.SelectedTable;
00226                 }
00227                                 bool success = ApplicationLogicLayer.TableManagement.RemoveTable(selectedTable, ref returnMessage);
00228                                 if (success)
00229                                 {
00230                                         this.Session[RAIS.UI.Common.Constants.TABLES_TAG] = null; //for resetting
00231                                         int selectedIndex = this.LBtable.SelectedIndex;
00232                                         UI.Common.TableManagement.InitializeTableListBoxByGroup(this.LBtable, this.SelectedTableGroup, this.ShowProtectors, this.ShowEvaluators);
00233                                         this.LBtable.SelectedIndex = -1;
00234                                         selectedIndex = (selectedIndex >= this.LBtable.Items.Count)
00235                                                 ? this.LBtable.Items.Count - 1
00236                                                 : selectedIndex;
00237                                         if (selectedIndex != -1)
00238                                                 this.LBtable.Items[selectedIndex].Selected = true;
00239                     CreateProtectors();
00240                                         this.EnableEditButton();
00241                                         this.EnableDeleteButton();
00242                                         this.EnableCreateHistoryTableButton();
00243                                 }
00244                                 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult,
00245                                                                                                                                         returnMessage,
00246                                                                                                                                         success);
00247 
00248                         }
00249                 }
00256                 protected void BTNcreateHistoryTable_Click(object sender, EventArgs e)
00257                 {
00258                                 string returnMessage = string.Empty;
00259                                 bool success = RAIS.ApplicationLogicLayer.TableManagement.CreateHistoryTable(this.SelectedTable, ref returnMessage);
00260                                 if (success)
00261                                 {
00262                                         this.Session[RAIS.UI.Common.Constants.TABLES_TAG] = null; //for resetting
00263                                         int selectedIndex = this.LBtable.SelectedIndex;
00264                                         UI.Common.TableManagement.InitializeTableListBoxByGroup(this.LBtable, this.SelectedTableGroup, this.ShowProtectors, this.ShowEvaluators);
00265                                         this.LBtable.SelectedIndex = -1;
00266                                         selectedIndex = (selectedIndex >= this.LBtable.Items.Count)
00267                                                 ? this.LBtable.Items.Count - 1
00268                                                 : selectedIndex;
00269                                         if (selectedIndex != -1)
00270                                                 this.LBtable.Items[selectedIndex].Selected = true;
00271                     CreateProtectors();
00272                                         this.EnableEditButton();
00273                                         this.EnableDeleteButton();
00274                                         this.EnableCreateHistoryTableButton();
00275                                 }
00276                                 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult,
00277                                                                                                                                         returnMessage,
00278                                                                                                                                         success);
00279                 }
00286                 protected void BTNscript_Click(object sender, EventArgs e)
00287                 {
00288                         string returnMessage = string.Empty;
00289 
00290                         bool success = RAIS.UI.Common.TableManagement.SaveTablesScript(ref returnMessage);
00291                         RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult,
00292                                                                                                                                 returnMessage,
00293                                                                                                                                 success);
00294                 }
00301                 protected void LBTNlogout_Click(object sender, EventArgs e)
00302                 {
00303                         UI.Common.AccessManagement.SignOut(this);
00304                 }
00311                 protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
00312                 {
00313                         UI.Common.UserManagement.ProcessTreeViewOnRedirect(this.TreeView1);
00314                 }
00315                 #endregion Event handlers
00316                 //*********************************************************************
00317                 #region Private helper methods
00318 
00321                 private void EnableDeleteButton()
00322                 {
00323                         this.BTNdelete.Enabled = this.LBtable.Items.Count > 0
00324                                 && this.SelectedTable != null
00325                 && this.SelectedTable.CustomTable;
00326             if (this.SelectedTable.HistoryTable)
00327             {
00328                 this.BTNdelete.Enabled = (GetParentTableForHistory(SelectedTable).CustomTable &&
00329                                     !ApplicationLogicLayer.TableManagement.IsTableContainData(this.SelectedTable)) ||
00330                                     GetParentTableForHistory(SelectedTable).Name == SelectedTable.Name;
00331             }
00332                                 //&& !this.SelectedTable.HistoryTable;
00333                 }
00337                 private void EnableEditButton()
00338                 {
00339                         this.BTNedit.Enabled = this.LBtable.Items.Count > 0
00340                                 && this.SelectedTable != null;
00341                 }
00345                 private void EnableCreateHistoryTableButton()
00346                 {
00347                         this.BTNcreateHistoryTable.Enabled = this.LBtable.Items.Count > 0
00348                                 && this.SelectedTable != null
00349                                 && this.SelectedTable.AddHistoryAllowed;
00350                                 //&& (this.SelectedTable.Type == RAIS.Common.TableManagement.Table.TableType.Single)
00351                                 //&& !this.SelectedTable.HistoryTable;
00352                 }
00353 
00354         private void CreateProtectors()
00355         {
00356             this.BTNdelete.Attributes.Add("onclick", string.Format("javascript: return confirm('{0}');", RAIS.Common.Messages.DELETE_QUESTION_CUSTOM_TABLES.Replace("'", "\\'")));
00357             this.BTNcreateHistoryTable.Attributes.Add("onclick", string.Format("javascript: return confirm('{0}');", RAIS.Common.Messages.CREATE_HISTORY_TABLE_QUESTION.Replace("'", "\\'")));
00358         }
00359 
00360         private RAIS.Common.TableManagement.Table GetParentTableForHistory(RAIS.Common.TableManagement.Table table)
00361         {
00362             string tableName = SelectedTable.Name.Substring(0, table.Name.Length - 8);
00363             Tables tabs = (Tables)this.Session[RAIS.UI.Common.Constants.TABLES_TAG];
00364             return tabs.ContainsKey(tableName) ? tabs[tableName] : table;
00365         }
00366         #endregion Private helper methods
00367         }
00368 }